import 'package:flutter/material.dart';

// 微信顶部导航栏右侧按钮：加号图标及下拉菜单,todo：待优化，小箭头的绘制
Widget popupMenuWidget() {
  return MenuAnchor(
    alignmentOffset: const Offset(-110, 20),
    style: const MenuStyle(
      backgroundColor: WidgetStatePropertyAll(Color(0xFF4c4c4c)),
    ),
    menuChildren: [
      _menuItemWidget('发起群聊', 'assets/images/popMenus/ic_chat.png', () {}),
      _dividerWidget(),
      _menuItemWidget('添加朋友', 'assets/images/popMenus/ic_add.png', () {}),
      _dividerWidget(),
      _menuItemWidget('扫一扫', 'assets/images/popMenus/ic_scan.png', () {} ),
      _dividerWidget(),
      _menuItemWidget('收付款', 'assets/images/popMenus/ic_pay.png', () {
        debugPrint('收付款');
      }),
    ],
    builder: (BuildContext context, MenuController controller, Widget? child) {
      return InkWell(
        onTap: () {
          if (controller.isOpen) {
            controller.close();
          } else {
            controller.open();
          }
        },
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: Image.asset('assets/images/common/add.png', width: 22,),
        ),
      );
    },
  );
}

// 每一项内容
Widget _menuItemWidget(String title, String imgUrl, VoidCallback onPressed) {
  return SizedBox(
    height: 50,
    child: MenuItemButton(
      onPressed: onPressed,
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        child: Row(
          children: [
            Image.asset(imgUrl, width: 18,),
            const SizedBox(width: 6,),
            Text(title, style: const TextStyle(color: Colors.white, fontSize: 18,),),
          ],
        ),
      ),
    ),
  );
}

// 分割线
Widget _dividerWidget() {
  return const Divider(
    height: 1,
    thickness: 1,
    color: Colors.white10,
    indent: 36,
    endIndent: 0,
  );
}

// 向上的箭头
Widget _arrowUpWidget() {
  return SizedBox(
    height: 32,
    child: Image.asset('assets/images/popMenus/ic_menu_up_arrow.png', width: 16,)
  );
}